{include file="public/header" /}

<div class="layui-card">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title">
                <li class="layui-this">基本信息</li>
            </ul>

            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">
                    <form class="layui-form layui-form-pane" action="/admin/news/single" method="post" id="add">
                        <input type="hidden" name="id" value="{$v.id}">
                        <input type="hidden" name="pid" value="{$v.pid}">
                        <input type="hidden" name="ty" value="{$v.ty}">
                        <input type="hidden" name="tty" value="{$v.tty}">
                        <input type="hidden" name="ttty" value="{$v.ttty}">


                        {if condition="in_array(1,$arr)"}
                            <div class="layui-form-item">
                                <label class="layui-form-label">标题</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" value="{$v.title}" required lay-verify="required" placeholder="请输入标题" class="layui-input">
                                </div>
                                {if condition="in_array(3,$arr)"}<input type="checkbox" class="checkbox" lay-skin='primary' name="isgood" value="1" title="推荐" {my:get_my_checked($v['isgood'],1)}>{/if}
                                {if condition="in_array(4,$arr)"}<input type="checkbox" class="checkbox" lay-skin='primary' name="istop" value="1" title="置顶" {my:get_my_checked($v['istop'],1)}>{/if}
                            </div>
                        {/if}

                        {if condition="in_array(2,$arr)"}
                            <div class="layui-form-item">
                                <label class="layui-form-label">副标题</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="ftitle" value="{$v.ftitle}" required lay-verify="required" placeholder="请输入副标题" class="layui-input">
                                </div>
                            </div>
                        {/if}

                        {if condition="in_array(5,$arr)"}
                            <div class="layui-form-item">
                                <label class="layui-form-label">外链</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="linkurl" value="{$v.linkurl}" required lay-verify="required" placeholder="请输入外链" class="layui-input">
                                </div>
                            </div>
                        {/if}

                        {if condition="in_array(6,$arr)"}
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">
                                    <span class='x-red'>*</span>简介</label>
                                <div class="layui-input-block">
                                    <textarea placeholder="请输入内容" name="introduce" class="layui-textarea">{$v.introduce}</textarea>
                                </div>
                            </div>
                        {/if}

                        {if condition="in_array(7,$arr)"}
                        <div class="layui-form-item">
                            <label class="layui-form-label">SEO关键字</label>
                            <div class="layui-input-inline">
                                <input type="text" name="seokeywords" value="{$v.seokeywords}" required lay-verify="required" placeholder="请输入外链" class="layui-input">
                            </div>
                        </div>
                        {/if}
                        {if condition="in_array(8,$arr)"}
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">
                                <span class='x-red'>*</span>SEO描述</label>
                            <div class="layui-input-block">
                                <textarea placeholder="请输入SEO描述" name="seodescription" class="layui-textarea">{$v.seodescription}</textarea>
                            </div>
                        </div>
                        {/if}

                        {if condition="in_array(9,$arr)"}
                            <div class="layui-form-item">
                                <label for="link" class="layui-form-label">
                                    <span class="x-red">*</span>文章内容
                                </label>
                                <div class="layui-input-inline">
                                    <textarea  id="content" placeholder="" name="content">{$v.content}</textarea>
                                </div>
                            </div>


                        {/if}

                        {if condition="in_array(10,$arr)"}
                            <?php $course = controller("Common");?>
                            {for start="1" end="$v['imgnum']"}
                                <?php $zd="img$i";?>

                                <div class="layui-form-item">
                                    <label for="link" class="layui-form-label">
                                        <span class="x-red">*</span>{:$course->get_imgname($i,$v['pid'],$v['ty'],$v['tty'])}</label>
                                    <div class="layui-input-inline">
                                        <div class="site-demo-upbar">
                                            <button type="button" class="layui-btn" id="test{$i}"><i class="layui-icon"></i>上传图片</button><font color="red">图片大小:{:get_cfg_var("post_max_size")}内,图片尺寸：{:$course->get_imgsize($i,$v['pid'],$v['ty'],$v['tty'],$v['ttty'])}px</font>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item imgs" id="imgshow">
                                    <label  class="layui-form-label">{:$course->get_imgname($i,$v['pid'],$v['ty'],$v['tty'])}展示</label>

                                    <img src="{$v['img'.$i]}" id="pimages{$i}"  style="max-width: 200px;"/>
                                    <input id="avatar{$i}" name="img{$i}"    required="" type="hidden"  value="{$v['img'.$i]}">
                                </div>
                            {/for}
                        {/if}



                        {if condition="in_array(11,$arr)"}
                            <div class="layui-form-item">
                                <label class="layui-form-label">文件上传</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="file1" id="file1" value="{$v.file1}" placeholder="请选择文件上传" class="layui-input">
                                </div>
                                <button type="button" id="insert_file1" class="layui-btn" data-des="enclosure">
                                    <i class="layui-icon">&#xe67c;</i>上传附件
                                </button>

                                <font color="#FF0000">文件大小:{:get_cfg_var("post_max_size")}</font>
                            </div>
                        {/if}


                        {if condition="in_array(12,$arr)"}
                        <div class="layui-form-item">
                            <label class="layui-form-label">来源</label>
                            <div class="layui-input-inline">
                                <input type="text" name="source" value="{$v.source}" required lay-verify="required" placeholder="请输入来源" class="layui-input">
                            </div>
                        </div>
                        {/if}


                        {if condition="in_array(13,$arr)"}
                        <div class="layui-form-item">
                            <label class="layui-form-label">作者</label>
                            <div class="layui-input-inline">
                                <input type="text" name="author" value="{$v.author}" required lay-verify="required" placeholder="请输入作者" class="layui-input">
                            </div>
                        </div>
                        {/if}

                        {if condition="in_array(14,$arr)"}
                        <div class="layui-form-item">
                            <label class="layui-form-label">价格</label>
                            <div class="layui-input-inline">
                                <input type="text" name="price" value="{$v.price}" required lay-verify="required" placeholder="请输入价格" class="layui-input">
                            </div>
                        </div>
                        {/if}


                        {if condition="in_array(15,$arr)"}
                        <div class="layui-form-item">
                            <label class="layui-form-label">人气</label>
                            <div class="layui-input-inline">
                                <input type="text" name="hits" value="{$v.hits}" required lay-verify="required" placeholder="请输入人气" class="layui-input">
                            </div>
                        </div>
                        {/if}

                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class='x-red'>*</span>排序
                            </label>
                            <div class="layui-input-block">
                                <input type="text" name="disorder" autocomplete="off" value="{$v.disorder}" placeholder="排序值只能为数字"
                                       class="layui-input">
                            </div>
                        </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>状态
                        </label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="显示" {if condition="$v['status'] eq 1"} checked {/if}>
                            <div class="layui-unselect layui-form-radio layui-form-radioed">
                                <i class="layui-anim layui-icon layui-anim-scaleSpring"></i>
                                <div>显示</div>
                            </div>
                            <input type="radio" name="status" value="0" title="隐藏" {if condition="$v['status'] eq 0"} checked {/if}>
                            <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
                                <div>隐藏</div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>时间
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="sendtime" value="{:date('Y-m-d H:i:s',$v.sendtime)}" readonly placeholder="请选择发布时间"  class="layui-input datetime">

                        </div>
                    </div>



                        <script type="text/javascript" src="/static/admin/lib/layui/layui.js"></script>
                        <script type="text/javascript" src="/static/admin/js/mylayui.js?v=v1.3.5"></script>






                    <div class="layui-form-item">
                        <button class="layui-btn" type="submit" lay-filter="add" lay-submit="">
                            保存
                        </button>
                    </div>
                    <div style="height:100px;"></div>
                </div>



            </div>

        </div>
</div>

<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    UE.getEditor('content',{initialFrameWidth:800,initialFrameHeight:600,});
</script>
<script>
    layui.use(['element','layer','form','upload'], function(){
        var  $ = layui.jquery;//jquery
        var lement = layui.element;//面包导航
        var layer = layui.layer;//弹出层
        var form = layui.form;
        var upload = layui.upload;



        //图片上传接口
        // layui.upload({
        //   url: './upload.json' //上传接口
        //   ,success: function(res){ //上传成功后的回调
        //       console.log(res);
        //     $('#LAY_demo_upload').attr('src',res.url);
        //   }
        // });
        //指定允许上传的文件类型
    <?php for($i=1;$i<10;$i++){?>
        upload.render({

            elem: '#test<?php echo $i;?>'
                // ,url: 'https://httpbin.org/post' //改成您自己的上传接口
                ,url: '/admin/news/uploads' //改成您自己的上传接口
                ,accept: 'file' //普通文件
                ,done: function(data){
                $('#pimages<?php echo $i;?>').attr('src',data.msg);
                $('#avatar<?php echo $i;?>').val(data.msg);
                // $('#pimages').attr('src',"222");
                layer.msg('上传成功');
                console.log(data.msg);
            },

    });
        <?php }?>

        //监听提交
        form.on('submit(add)', function(data){
            var title=$("input[name='title']").val();
            //var content=$("textarea[name='content']").val();

            var article_category_id=$('#article_category_id option:selected') .val();//所属文章类型
            //alert(title);
            //var form=$("#cate_add").serialize();
            if(title==""){
                layer.msg('文章标题不能为空',{icon:5,time:2000});return false;
            }
            if(article_category_id==""){
                layer.msg('文章类型不能为空',{icon:5,time:2000});return false;
            }
            /*if(content){
                layer.msg("文章内容不能为空！",{icon:5,time:2000});return false;
          }*/
            var data = data.field;
            $.ajax({
                type:"post",
                url:"",
                data:data,
                dataType:"json",
                success:function(data){
                    if(data.status==1){
                        layer.msg(data.info, {icon: 6,time:2000},function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                        return false;

                    }else{
                        layer.msg(data.info,{icon:5,time:2000});return false;
                    }
                }

            });

        });

    })
</script>


    <script>
        layui.use(['laydate','form'], function(){
            var laydate = layui.laydate;
            var  form = layui.form;

        });

    </script>
    <!--栏目缩略图上传-->
    <script>
        function upload(obj,id){
            var formData = new FormData();
            formData.append('images', $('#previewImg')[0].files[0]);
            formData.append('id', id);//将id追加再id中
            layer.msg('图片上传中', {icon: 16});
            $.ajax({
                type:"post",
                processData: false,
                contentType: false,
                url:"",
                data:formData,
                success:function(data){
                    if(data.status == 1){
                        console.log(data.image_name);
                        layer.closeAll('loading');
                        //layer.msg(data.info,{icon:1,time:1000});
                        $("#pimages").attr('src',data.image_name);
                        $("#avatar").val(data.image_name);
                        $(".imgs").show();
                        return false;
                    }else{
                        layer.msg(data.info,{icon:2,time:1000});
                    }
                }
            });
        }
    </script>

    </body>
    </html>